//
//  NSTimer+NonRetain.m
//  BPGKeepDemo
//
//  Created by baipeng on 2018/5/10.
//  Copyright © 2018年 Apple Inc. All rights reserved.
//

#import "NSTimer+NonRetain.h"


@interface ForWardingTarget : NSObject
@property (nonatomic,weak) id realTarget;
@end

@implementation ForWardingTarget
-(instancetype)initWithRealTarget:(id)target{
    if (self == [super init]) {
        _realTarget = target;
    }
    return self;
}
-(id)forwardingTargetForSelector:(SEL)aSelector{
    return self.realTarget;
}
@end

@implementation NSTimer (NonRetain)
+(NSTimer *)scheduledNonRetainTimerWithTimeInterval:(NSTimeInterval)interval
                                             target:(id)aTarget
                                           selector:(SEL)aSelector
                                           userInfo:(id)userInfo
                                            repeats:(BOOL)repeats{
    ForWardingTarget *target = [[ForWardingTarget alloc] initWithRealTarget:aTarget];
    return [NSTimer scheduledTimerWithTimeInterval:interval target:target selector:aSelector userInfo:userInfo repeats:repeats];
}
@end
